package com.ymatou.iapi.csim.testcase;

import com.ymatou.iapi.csim.parameter.OnlineBean;
import com.ymatou.iapi.csim.service.OnlineCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;

import org.junit.*;
import org.junit.experimental.categories.Category;





import com.ymatou.iapi.csim.parameter.OnlineBean;
import com.ymatou.iapi.csim.service.OnlineCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_onlinecs;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.TestDataManager;
/**
*客服上线,可以接收新会话
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Online{
	private static OnlineBean bean;
	private static OnlineCall call;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private static ymt_onlinecsWapper onlinecsWapper=new ymt_onlinecsWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("客服上线,可以接收新会话");
	}

	@Before
	public void caseUp() {
		bean=new OnlineBean();
		call=new OnlineCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Online_001() {
		Logger.start(true,"客服上线-该客服未上线");
		try {
			//查询是否有在线客服 1，2
    		service.getOnlineCS();
			bean.setCsId(csId);
			call.setData(bean);
			call.callService();	
			Logger.verifyEquals("0",call.getResult().get("ErrorCode").toString(), "验证返回的errorCode");
			Logger.verifyEquals("",call.getResult().get("ErrorMessage"), "验证返回的errorMessage");
			Logger.verifyEquals(true,call.getResult().get("Success"), "验证返回的Success");
			Logger.verifyEquals("200",call.getStatus(), "验证返回的status");
			//验证数据库
			ymt_onlinecs onlinecs=onlinecsWapper.selectBy(MapUtil.hashMap("CSId",csId)).get(0);
			Logger.verifyEquals(0,onlinecs.getStatus(), "验证数据库中的Status");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Online_002() {
		Logger.start(true,"客服上线-该客服已上线，再调上线");
		try {
			//查询是否有在线客服 1，2
    		service.getOnlineCS();
			bean.setCsId(csId);
			call.setData(bean);
			call.callService();
			call.callService();	
			Logger.verifyEquals("0",call.getResult().get("ErrorCode").toString(), "验证返回的errorCode");
			Logger.verifyEquals("",call.getResult().get("ErrorMessage"), "验证返回的errorMessage");
			Logger.verifyEquals(true,call.getResult().get("Success"), "验证返回的Success");
			Logger.verifyEquals("200",call.getStatus(), "验证返回的status");
			//验证数据库
			ymt_onlinecs onlinecs=onlinecsWapper.selectBy(MapUtil.hashMap("CSId",csId)).get(0);
			Logger.verifyEquals(0,onlinecs.getStatus(), "验证数据库中的Status");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}